-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
92 lines (78 loc) · 2.86 KB
/
app.js
File metadata and controls
92 lines (78 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const menu = document.querySelector('#mobile-menu');
const menuLink = document.querySelector('.nav-menu');
const navLogo = document.querySelector('#navbar__logo');
//this code is for the mobile version animation of dropdown function
// Display Mobile Menu
menu.addEventListener('click', function() {
menu.classList.toggle('is-active');
menuLink.classList.toggle('active');
})
window.onload = () => {
document.getElementById('submit').addEventListener('click', (e) => {
e.preventDefault();
let name = document.getElementById('name').value;
let email = document.getElementById('email').value;
re_name = /[a-zA-Z_\s\-]{3,32}/
re_email = /([a-zA-Z_\.\-\d]+)@([a-zA-Z_\.\-\d]+)\.([a-zA-Z]{2,10})/
if ((!re_name.test(name)) || (!re_email.test(email))) {
alert('wrong try again')
location.onload();
}
const url = "https://mudfoot.doc.stu.mmu.ac.uk/node/api/mailinglist";
const data = {
"name": name,
"email": email
};
console.table(data);
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => {
if (response.status === 200) {
return response.json();
} else if (response.status === 400) {
throw 'bad data sent to the server';
} else {
throw "something went wrong";
}
})
.then(obj => {
document.getElementById("message").innerHTML = obj.data.name + ' has been added'
})
.catch(err => {
document.getElementById("message").innerHTML = err
})
})
}
const gethalloffame = () => {
const url = "https://mudfoot.doc.stu.mmu.ac.uk/node/api/halloffame";
fetch(url, {
method: "get",
})
.then(response => {
if (response.status === 200) {
return response.json();
} else {
throw "something went wrong";
}
})
.then((resJson) => {
let = tableHTML = "";
for (let i = 0; i < resJson.length; i++) {
tableHTML += "<tr>";
tableHTML += "<td>" + resJson[i]["movie_id"] + "</td>";
tableHTML += "<td>" + resJson[i]["movie_name"] + "</td>";
tableHTML += "<td>" + resJson[i]["movie_year"] + "</td>";
tableHTML += "<td>" + resJson[i]["movie_director"] + "</td>";
tableHTML += "</tr>";
};
document.getElementById("movie-table-body").innerHTML = tableHTML;
})
.catch((error) => {
alert(error);
})
}